package com.itheima.mapper;

import com.itheima.entity.Student;
import com.itheima.entity.StudentQueryParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StudentMapper {

    /**
     * 分页查询
     * @param param
     * @return
     */
    List<Student> list(StudentQueryParam param);

    /**
     * 添加学生
     * @param student
     */
    void add(Student student);

    /**
     * 根据id查询学生
     * @param id
     * @return
     */
    @Select("select * from student where id = #{id}")
    Student getById(Integer id);

    /**
     * 修改学生
     * @param student
     */
    void update(Student student);

    /**
     * 批量删除学生
     * @param ids
     */
    void delete(List<Integer> ids);

    /**
     * 添加违纪
     * @param id
     * @param score
     */
    @Update("update student set violation_count = violation_count + 1 , violation_score = violation_score + #{score} where id = #{id}")
    void missScore(Integer id, Short score);

    /**
     * 根据班级id查询学生
     * @param id
     */
    @Select("select count(*) from student where clazz_id = #{id}")
    Integer getByClazzId(Integer id);
}
